#include <windows.h>
#include <WinBase.h>		// for GMEM_FIXED
#include <sql.h>

#include "op_string.h"
/*
*---------------
Author : coanor(coanor1126@hotmail.com)
Updated: 16 Feb 2009
Defines: strxmov()

strxmov(dst, src1, ..., srcn, NullS)
moves the concatenation of src1,...,srcn to dst, terminates it
with a NUL character, and returns a pointer to the terminating NUL.
It is just like strmov except that it concatenates multiple sources.
Beware: the last argument should be the null character pointer.
Take VERY great care not to omit it!  Also be careful to use NullS
and NOT to use 0, as on some machines 0 is not the same size as a
character pointer, or not the same bit pattern as NullS.
*-----------------
*/
#if defined(WIN32) 
char *strglobaldup(const char *s)
{
	size_t nAvail;
	char *p;

	nAvail = strlen(s) + 1;
	p = (char*)GlobalAlloc(GMEM_FIXED, nAvail);
	memcpy (p, s, nAvail);

	return p;
}

#define opodbc_min(a, b) (((a) < (b)) ? (a) : (b))
char *strnglobaldup(const char *s, size_t n)
{
	size_t nAvail;
	char *p;

	if (!s)
		return 0;

	nAvail = opodbc_min(strlen(s) + 1, n + 1);

	if (nAvail < 1)
		return 0;

	p = (char *)GlobalAlloc(GMEM_FIXED, nAvail);
	memcpy(p, s, nAvail);
	p[nAvail - 1] = '\0';

	return p; 
}
#endif	/* defined WIN32 */